/*
 * @Author       : tfhappy
 * @Date         : 2020-07-06 23:30:43
 * @LastEditTime : 2020-07-10 00:33:41
 * @FilePath     : /giteecli/main.go
 * @Description  :
 */
package main

import (
	"log"
	"os"

	"gitee.com/tfhappy/giteecli/action"
	"gitee.com/tfhappy/giteecli/common"
	"github.com/urfave/cli/v2"
)

func main() {
	app := cli.NewApp()
	app.Name = "giteecli"
	app.Usage = "gitee cli tool"
	app.Flags = []cli.Flag{
		&cli.StringFlag{
			Name:        common.ACCOUNT,
			Aliases:     []string{"a"},
			Usage:       "gitee account(email addr)",
			DefaultText: "Default get GITEE_USEREMAIL from env",
			Value:       os.Getenv(common.GITEE_USEREMAIL),
		},
		&cli.StringFlag{
			Name:        common.USERNAME,
			Aliases:     []string{"u"},
			Usage:       "gitee user",
			DefaultText: "Default get GITEE_USERNAME from env",
			Value:       os.Getenv(common.GITEE_USERNAME),
		},
		&cli.StringFlag{
			Name:        common.PASSWORD,
			Aliases:     []string{"p"},
			Usage:       "gitee user password",
			DefaultText: "Default get GITEE_PASSWORD from env",
			Value:       os.Getenv(common.GITEE_PASSWORD),
		},
		&cli.StringFlag{
			Name:        common.CLIENTID,
			Aliases:     []string{"cid"},
			Usage:       "gitee client id. Learn more at https://gitee.com/api/v5/oauth_doc#/list-item-3",
			DefaultText: "Default get GITEE_CLIENTID from env",
			Value:       os.Getenv(common.GITEE_CLIENTID),
		},
		&cli.StringFlag{
			Name:        common.CLIENTSECRET,
			Aliases:     []string{"sec"},
			Usage:       "gitee client secret. Learn more at https://gitee.com/api/v5/oauth_doc#/list-item-3",
			DefaultText: "Default get GITEE_CLIENTSECRET from env",
			Value:       os.Getenv(common.GITEE_CLIENTSECRET),
		},
	}

	app.Commands = []*cli.Command{
		{
			Name:    "repository",
			Usage:   "repository actions",
			Aliases: []string{"repo"},
			Subcommands: []*cli.Command{
				{
					Name:   "create",
					Usage:  "create a repository",
					Action: action.CreateRepositoryAction,
					Flags: []cli.Flag{

						&cli.StringFlag{
							Name:     "name",
							Aliases:  []string{"n"},
							Usage:    "repository name",
							Required: true,
						},
						&cli.StringFlag{
							Name:    "description",
							Aliases: []string{"desc"},
							Usage:   "repository description",
						},
						&cli.StringFlag{
							Name:        "homepage",
							Usage:       "repository homepage",
							DefaultText: "https://gitee.com/{gitee-user}/{repo-name}",
						},
						&cli.BoolFlag{
							Name:  "has_issues",
							Usage: "has_issues",
							Value: true,
						},
						&cli.BoolFlag{
							Name:  "has_wiki",
							Usage: "has_wiki",
							Value: false,
						},
						&cli.BoolFlag{
							Name:  "can_comment",
							Usage: "can_comment",
							Value: true,
						},
						&cli.BoolFlag{
							Name:  "auto_init",
							Usage: "use readme init repo or not",
							Value: true,
						},
						&cli.StringFlag{
							Name:    "gitignore_template",
							Aliases: []string{"ignore"},
							Usage:   "gitignore_template",
							Value:   "Go",
						},
						&cli.StringFlag{
							Name:  "license_template",
							Usage: "license_template",
							Value: "Apache-2.0",
						},
						&cli.BoolFlag{
							Name:  "private",
							Usage: "private repo or not",
							Value: true,
						},
					},
				},
			},
		},
	}
	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}
